package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Ingre;
import com.ruoyi.system.service.IIngreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料Controller
 * 
 * @author ruoyi
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/system/ingre")
@Api(tags = "物料管理")
public class IngreController extends BaseController
{
    @Autowired
    private IIngreService ingreService;

    /**
     * 查询物料列表
     */
    @PreAuthorize("@ss.hasPermi('system:ingre:list')")
    @GetMapping("/list")
    @ApiOperation("查询物料列表")
    public TableDataInfo list(@RequestBody Ingre ingre, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize)
    {
        List<Ingre> list = ingreService.selectIngreList(ingre, pageNum, pageSize);
        Long total = ingreService.selectIngreCount(ingre);
        return getDataTable(list, total);
    }

    /**
     * 导出物料列表
     */
    @PreAuthorize("@ss.hasPermi('system:ingre:export')")
    @Log(title = "物料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出物料列表")
    public void export(HttpServletResponse response, Ingre ingre)
    {
        List<Ingre> list = ingreService.selectIngreAll(ingre);
        ExcelUtil<Ingre> util = new ExcelUtil<Ingre>(Ingre.class);
        util.exportExcel(response, list, "物料数据");
    }

    /**
     * 获取物料详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ingre:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取物料详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ingreService.selectIngreById(id));
    }

    /**
     * 新增物料
     */
    @PreAuthorize("@ss.hasPermi('system:ingre:add')")
    @Log(title = "物料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增物料")
    public AjaxResult add(@RequestBody Ingre ingre)
    {
        return toAjax(ingreService.insertIngre(ingre));
    }

    /**
     * 修改物料
     */
    @PreAuthorize("@ss.hasPermi('system:ingre:edit')")
    @Log(title = "物料", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    @ApiOperation("修改物料")
    public AjaxResult edit(@RequestBody Ingre ingre)
    {
        return toAjax(ingreService.updateIngre(ingre));
    }

    /**
     * 删除物料
     */
    @PreAuthorize("@ss.hasPermi('system:ingre:remove')")
    @Log(title = "物料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除物料")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ingreService.deleteIngreByIds(ids));
    }
}
